package com.dongdongshop.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.dongdongshop.data.DataResult;
import com.dongdongshop.data.ResponseStausEnum;
import com.dongdongshop.pojo.TbContent;
import com.dongdongshop.pojo.TbContentCategory;
import com.dongdongshop.service.ContentService;
import com.dongdongshop.util.PageBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @Description
 * @ClassName ContentController
 * @Author RC
 * @date 2020.12.16 16:22
 */
@Controller
@RequestMapping("content")
public class ContentController {
    @Reference(timeout = 100000,check = false)
    private ContentService contentService;
    private static final Logger logger = LoggerFactory.getLogger(ContentController.class);

    @RequestMapping("getContentList")
    @ResponseBody
    public DataResult getContentList(@RequestParam(defaultValue = "1") Integer pageNumber, @RequestParam(defaultValue = "5") Integer pageSize) {
        try {
            logger.info("进入广告管理查询方法");
            PageBean<TbContent> contentList = contentService.getContentList(pageNumber, pageSize);
            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(contentList);

        } catch (Exception e) {
            logger.info("查询失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //新增
    @RequestMapping("saveContentCagetory")
    @ResponseBody
    public DataResult saveContentCagetory(TbContent tbContent) {
        try {
            logger.info("进入广告新增方法");
            contentService.saveContentCagetory(tbContent);
            return DataResult.response(ResponseStausEnum.SUSSCESS);

        } catch (Exception e) {
            logger.info("查询失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //回显
    @RequestMapping("getContentListById/{id}")
    @ResponseBody
    public DataResult getContentListById(@PathVariable("id")Long id) {
        try {
            logger.info("进入广告回显方法");
            TbContent content = contentService.getContentListById(id);
            return DataResult.response(ResponseStausEnum.SUSSCESS).setData(content);

        } catch (Exception e) {
            logger.info("加载失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //修改
    @RequestMapping("updateContentCagetory")
    @ResponseBody
    public DataResult updateContentCagetory(TbContent tbContent) {
        try {
            logger.info("进入广告新增方法");
            contentService.updateContentCagetory(tbContent);
            return DataResult.response(ResponseStausEnum.SUSSCESS);

        } catch (Exception e) {
            logger.info("查询失败", e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }
    //批量删除
    @RequestMapping("deleteBatchContent/{ids}")
    @ResponseBody
    public DataResult deleteBatchContent(@PathVariable("ids")Long[] ids){
        try{
            logger.info("进入删除方法");
            contentService.deleteBatchContent(ids);
            return DataResult.response(ResponseStausEnum.SUSSCESS);

        }catch (Exception e){
            logger.info("删除失败",e);
            return DataResult.response(ResponseStausEnum.INTERNAL_SERVER_ERROR);
        }
    }


}
